#
# @lc app=leetcode.cn id=3 lang=python3
#
# [3] 无重复字符的最长子串
#

# @lc code=start
class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        # 思路一：滑动窗口法
        temp_str = ''
        max_len, current_len = 0, 0
        for i in range(len(s)):
            if s[i] not in temp_str:
                temp_str += s[i]
                current_len += 1
            else:
                index = temp_str.index(s[i])
                temp_str = temp_str[index+1:]
                temp_str += s[i]
                current_len = len(temp_str)
            if max_len < current_len:
                max_len = current_len
        
        return max_len
            
# @lc code=end

